﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace PacoToolKit.Json
{
    /// <summary>
    ///LinqToJson  http://www.newtonsoft.com/json
    /// </summary>
    public static class LinqToJson
    {
        /// <summary>
        /// Parsing JSON text
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static JObject ParsingJsonTextToObject(string json)
        {
            return JObject.Parse(json);
        }

        /// <summary>
        /// Parsing JSON text
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static JArray ParsingJsonTextToArray(string json)
        {
            return JArray.Parse(json);
        }

        /// <summary>
        /// Loading JSON from a file
        /// </summary>
        /// <param name="filename">(like @"c:\person.json"))</param>
        /// <returns></returns>
        public static JObject LoadJsonFromFile(string filename)
        {
            using (StreamReader reader = System.IO.File.OpenText(filename))
            {
                return (JObject)JToken.ReadFrom(new JsonTextReader(reader));
            }
        }
    }
}
